#include <bits/stdc++.h>

using namespace std;

const int N = 50010;
int id[N];
int main()
{
    int n;
    cin >> n;
    memset(id, -1, sizeof id);
    id[0] = 0;
    int sum = 0, ret = 0;
    for(int i = 1;i <= n;i ++)
    {
        int x; cin >> x;
        sum = (sum + x) % 7;
        if(id[sum] != -1) ret = max(ret , i - id[sum]);
        else id[sum] = i;
    }
    cout << ret << endl;
    return 0;
}